package gr.gousiosg.javacg;

import org.apache.bcel.classfile.*;
import org.apache.bcel.generic.*;

import java.io.*;
import java.util.*;
 
public class MethodCallAnalyzer {
    public static void main(String[] args) throws IOException {
        // 假设args[0]是类文件的路径
//        JavaClass javaClass = new ClassParser(args[0]).parse();
//        ConstantPool constantPool = javaClass.getConstantPool();
//
//        // 分析每个方法
//        for (Method method : javaClass.getMethods()) {
//            System.out.println("分析方法: " + method.getName());
//            MethodGen methodGen = new MethodGen(method, constantPool);
//            InstructionList instructions = methodGen.getInstructionList();
//
//            // 遍历指令
//            for (InstructionHandle handle : instructions) {
//                Instruction instruction = handle.getInstruction();
//                // 检查invokevirtual指令，即虚方法调用
//                if (instruction instanceof INVOKEVIRTUAL) {
//                    System.out.println(((INVOKEVIRTUAL) instruction).getIndex());
////                    ((INVOKEVIRTUAL) instruction).getReferenceType(constantPool);
////                    MethodReference reference = (MethodReference) constantPool.getConstant(((INVOKEVIRTUAL) instruction).getIndex());
////                    System.out.println("调用方法: " + reference.getName());
//                }
//            }
//        }
    }
}